package com.kurumi.controller;

import java.io.OutputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kurumi.pojo.RespondResult;
import com.kurumi.query.MedicalRecordDRGsQuery;
import com.kurumi.query.StatisticsAnalysisQuery;
import com.kurumi.service.SolrService;
import com.kurumi.service.StatisticsAnalysisService;
import com.kurumi.util.DateUtil;
import com.kurumi.util.ExcelUtils;
import com.kurumi.util.JsonUtil;
import com.kurumi.util.ListPagination;

@Controller
@RequestMapping("/statistics_analysis")
public class StatisticsAnalysisController {

	@Autowired
	private StatisticsAnalysisService statisticsAnalysisService;

	@Autowired
	private SolrService solrService;

	@GetMapping("/statistics_analysis_index")
	public String statisticsAnalysisIndex(){
		return "statistics_analysis_index.default";
	}

	@GetMapping("/diag_top_10_page")
	public String diagTop10Page(){
		return "statistics_analysis/diag_top_10_page";
	}

	@GetMapping("/medical_quality_indicators_page")
	public String medicalQualityIndicatorsPage(){
		return "statistics_analysis/medical_quality_indicators_page";
	}

	@GetMapping("/sequence_diag_page")
	public String sequenceDiagPage(){
		return "statistics_analysis/sequence_diag_page";
	}

	/**
	 * 十八种重点疾病page
	 * @return
	 */
	@GetMapping("/eighteen_key_diseases_page")
	public String eighteenKeyDiseasesPage(){
		return "statistics_analysis/eighteen_key_diseases_page";
	}

	/**
	 * 非计划再入院page
	 * @return
	 */
	@GetMapping("/unplan_re_operate_page")
	public String unplanReOperatePage(){
		return "statistics_analysis/unplan_re_operate_page";
	}

	/**
	 * 非计划再手术page
	 * @return
	 */
	@GetMapping("/unplan_re_hospital_page")
	public String unplanReHospitalPage(){
		return "statistics_analysis/unplan_re_hospital_page";
	}

	/**
	 * 二级医院重点手术Page
	 * @return
	 */
	@GetMapping("/seven_key_surgery_page")
	public String sevenKeySurgeryPage(){
		return "statistics_analysis/seven_key_surgery_page";
	}

	/**
	 * 三级医院重点手术Page
	 * @return
	 */
	@GetMapping("/tertiary_hospital_key_surgery_page")
	public String tertiaryHospitalKeySurgeryPage(){
		return "statistics_analysis/tertiary_hospital_key_surgery_page";
	}

	/**
	 * 三级医院恶性肿瘤Page
	 * @return
	 */
	@GetMapping("/tertiary_hospital_malignant_tumor_page")
	public String tertiaryHospitalMalignantTumorPage(){
		return "statistics_analysis/tertiary_hospital_malignant_tumor_page";
	}

	@RequestMapping("/diag_top_10")
	@ResponseBody
	public RespondResult diagTop10(StatisticsAnalysisQuery params){
		RespondResult respondResult = null;
		try {
			List<Map<String,Object>> datas = solrService.diagTop10Facet(params);
			params.setTotalCounts(datas.size());
			ListPagination<Map<String,Object>> pagination = new ListPagination<Map<String,Object>>(datas, params.getCurrentPage(), params.getPageSize());
			params.setDatas(pagination.getList());
			/*List<Integer> pageTypeIds = printService.getMrPageTypeIdsByPrintTypeId(printerTypeId);*/
			respondResult = new RespondResult(true, RespondResult.successCode, "查询成功", params);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			respondResult = new RespondResult(false, RespondResult.errorCode, e.getMessage(),e.getMessage());
		}

		return respondResult;
	}

	@GetMapping("/operate_top_10_page")
	public String operateTop10Page(){
		return "statistics_analysis/operate_top_10_page";
	}


	@RequestMapping("/operate_top_10")
	@ResponseBody
	public RespondResult operateTop10(StatisticsAnalysisQuery params){
		RespondResult respondResult = null;
		try {
			List<Map<String,Object>> datas = solrService.operateTop10Facet(params);
			params.setTotalCounts(datas.size());
			ListPagination<Map<String,Object>> pagination = new ListPagination<Map<String,Object>>(datas, params.getCurrentPage(), params.getPageSize());
			params.setDatas(pagination.getList());
			/*List<Integer> pageTypeIds = printService.getMrPageTypeIdsByPrintTypeId(printerTypeId);*/
			respondResult = new RespondResult(true, RespondResult.successCode, "查询成功", params);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			respondResult = new RespondResult(false, RespondResult.errorCode, e.getMessage(),e.getMessage());
		}

		return respondResult;
	}

	@GetMapping("/medical_pay_type_page")
	public String medicalPayTypePage(){
		return "statistics_analysis/medical_pay_type_page";
	}


	@RequestMapping("/medical_pay_type_analysis")
	@ResponseBody
	public RespondResult medicalPayTypeAnalysis(StatisticsAnalysisQuery params){
		RespondResult respondResult = null;
		try {
			Map<String, Object> datas=new HashMap<String, Object>();
			int totalCount = statisticsAnalysisService.getMedicalRecordCount(params.getOutHospitalStartDate(), params.getOutHospitalEndDate());
			datas.put("totalCount", totalCount);
			List<Map<String,Object>> medicalPayTypeAnalysis = statisticsAnalysisService.getMedicalPayTypeAnalysis(params.getOutHospitalStartDate(), params.getOutHospitalEndDate());
			List<Map<String, Object>> pageDataList = new ArrayList<Map<String, Object>>();
			int sumCount = 0;
			for (Map<String, Object> medicalPayType : medicalPayTypeAnalysis) {
				Map<String, Object> pageDataMap=new HashMap<String, Object>();
				String medicalPayTypeName=(String)medicalPayType.get("medical_pay_type_name");
				if(medicalPayTypeName !=null){
					pageDataMap.put("label",medicalPayTypeName.replaceAll("\"", ""));
				}else{
					pageDataMap.put("label","");
				}

				Object countObj = medicalPayType.get("count");
				if(countObj !=null){
					int number = ((Long)countObj).intValue();
					pageDataMap.put("value",number);
					sumCount +=number;
				}else{
					pageDataMap.put("value",0);
				}

                pageDataList.add(pageDataMap);
			}
			if(totalCount > sumCount){
				Map<String, Object> pageDataMap=new HashMap<String, Object>();
				pageDataMap.put("label","未知");
				pageDataMap.put("value",totalCount - sumCount);
				pageDataList.add(pageDataMap);
			}
			datas.put("items", pageDataList);
			/*List<Integer> pageTypeIds = printService.getMrPageTypeIdsByPrintTypeId(printerTypeId);*/
			respondResult = new RespondResult(true, RespondResult.successCode, "查询成功", datas);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			respondResult = new RespondResult(false, RespondResult.errorCode, e.getMessage(),e.getMessage());
		}

		return respondResult;
	}

	@GetMapping("/in_hospital_type_page")
	public String inHospitalTypePage(){
		return "statistics_analysis/in_hospital_type_page";
	}


	@RequestMapping("/in_hospital_type_analysis")
	@ResponseBody
	public RespondResult inHospitalTypeAnalysis(StatisticsAnalysisQuery params){
		RespondResult respondResult = null;
		try {
			Map<String, Object> datas=new HashMap<String, Object>();
			int totalCount = statisticsAnalysisService.getMedicalRecordCount(params.getOutHospitalStartDate(), params.getOutHospitalEndDate());
			datas.put("totalCount", totalCount);
			List<Map<String,Object>> inHospitalTypeAnalysis = statisticsAnalysisService.getInHospitalTypeAnalysis(params.getOutHospitalStartDate(), params.getOutHospitalEndDate());
			List<Map<String, Object>> pageDataList = new ArrayList<Map<String, Object>>();
			int sumCount = 0;
			for (Map<String, Object> inHospitalType : inHospitalTypeAnalysis) {
				Map<String, Object> pageDataMap=new HashMap<String, Object>();
				String inHospitalTypeName=(String)inHospitalType.get("in_hospital_type_name");
				if(inHospitalTypeName !=null){
					pageDataMap.put("label",inHospitalTypeName.replaceAll("\"", ""));
				}else{
					pageDataMap.put("label","");
				}

				Object countObj = inHospitalType.get("count");
				if(countObj !=null){
					int number = ((Long)countObj).intValue();
					pageDataMap.put("value",number);
					sumCount +=number;
				}else{
					pageDataMap.put("value",0);
				}

                pageDataList.add(pageDataMap);
			}
			if(totalCount > sumCount){
				Map<String, Object> pageDataMap=new HashMap<String, Object>();
				pageDataMap.put("label","未知");
				pageDataMap.put("value",totalCount - sumCount);
				pageDataList.add(pageDataMap);
			}
			datas.put("items", pageDataList);
			/*List<Integer> pageTypeIds = printService.getMrPageTypeIdsByPrintTypeId(printerTypeId);*/
			respondResult = new RespondResult(true, RespondResult.successCode, "查询成功", datas);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			respondResult = new RespondResult(false, RespondResult.errorCode, e.getMessage(),e.getMessage());
		}

		return respondResult;
	}

	/**
	 * 十八种重点疾病
	 * @param params
	 * @return
	 */
	@GetMapping("/eighteen_key_diseases")
	@ResponseBody
	public RespondResult eighteenKeyDiseases(StatisticsAnalysisQuery params){
		RespondResult respondResult = null;
		try {
			List<Map<String,Object>> datas = solrService.eighteenKeyDiseases(params);
			params.setTotalCounts(datas.size());
			params.setDatas(datas);
			/*List<Integer> pageTypeIds = printService.getMrPageTypeIdsByPrintTypeId(printerTypeId);*/
			respondResult = new RespondResult(true, RespondResult.successCode, "查询成功", params);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			respondResult = new RespondResult(false, RespondResult.errorCode, e.getMessage(),e.getMessage());
		}

		return respondResult;
	}

	@GetMapping("/eighteen_key_diseases_export_excel")
	public void eighteenKeyDiseasesExportExcel(StatisticsAnalysisQuery params,HttpServletResponse response){
		OutputStream out = null;
		try{
			params.setPageSize(null);
			/*
			medicalRecords = medicalRecordDRGsService.getCodingExport(params);*/
			response.setContentType("applicationnd.ms-excel");
			String title= "重点疾病"+params.getKeyDiseasesCode()+"导出"+DateUtil.dateFormat(new Date());
			StringBuilder downLoadFileName = new StringBuilder();
			downLoadFileName = new StringBuilder(
					"attachment;filename=");
			downLoadFileName.append(title)
					.append(".xls");
			/*downLoadFileName.append(title).append(DateUtil.dateFormat(new Date()))
			.append(".dbf");*/
			String encodeStr = new String(downLoadFileName.toString().getBytes(
					"GB2312"), "ISO_8859_1");
			response.addHeader("Content-Disposition", encodeStr);
			out = response.getOutputStream();
			List<String> headers = new ArrayList<String>();
			headers.add("住院号");
			headers.add("姓名");
			headers.add("出院日期");
			headers.add("出院病区名称");
			headers.add("是否死亡");
			headers.add("住院天数");
			headers.add("是否15日再住院");
			headers.add("是否31日再住院");
			headers.add("主要诊断名称");
			headers.add("主要诊断编码");
			headers.add("其他诊断");
			headers.add("总费用");
			List<String> keys = new ArrayList<String>();
			keys.add("only_id");
			keys.add("patient_name");
			keys.add("out_hospital_date");
			keys.add("out_dept_name");
			keys.add("is_death");
			keys.add("in_hospital_day_number");
			keys.add("is_15_rehospital");
			keys.add("is_31_rehospital");
			keys.add("main_diag");
			keys.add("main_diag_code");
			keys.add("other_diags");
			keys.add("total_cost");
			List<Map<String, String>> datas = solrService.eighteenKeyDiseasesForExport(params);
			ExcelUtils.exportExcel1(out,headers, keys, datas);
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
//非计划再住院导出
	@GetMapping("/unplan_re_hospital_export_excel")
	public void unplanReHospitalExportExcel(StatisticsAnalysisQuery params,HttpServletResponse response){
		OutputStream out = null;
		try{
			params.setPageSize(null);
			/*
			medicalRecords = medicalRecordDRGsService.getCodingExport(params);*/
			response.setContentType("applicationnd.ms-excel");
			String title= "非计划再住院记录导出"+DateUtil.dateFormat(new Date());
			StringBuilder downLoadFileName = new StringBuilder();
			downLoadFileName = new StringBuilder(
					"attachment;filename=");
			downLoadFileName.append(title)
					.append(".xls");
			/*downLoadFileName.append(title).append(DateUtil.dateFormat(new Date()))
			.append(".dbf");*/
			String encodeStr = new String(downLoadFileName.toString().getBytes(
					"GB2312"), "ISO_8859_1");
			response.addHeader("Content-Disposition", encodeStr);
			out = response.getOutputStream();
			List<String> headers = new ArrayList<String>();
			headers.add("住院号");
			headers.add("姓名");
			headers.add("出院日期");
			headers.add("离院方式");
			headers.add("总费用");
			headers.add("血费");
			headers.add("手术费");
			headers.add("住院天数");
			headers.add("是否非计划再住院");
			headers.add("距离上一次住院时间间隔");
			headers.add("本次住院与上一次住院是否因同一疾病（主要诊断）");
			headers.add("主要诊断编码");
			headers.add("主要诊断名称");

			List<String> keys = new ArrayList<String>();
			keys.add("only_id");
			keys.add("patient_name");
			keys.add("out_hospital_date");
			keys.add("str_out_hospital_type");
			keys.add("float_cost1");//总费用
			keys.add("float_cost22");//血费
			keys.add("float_cost13");//手术费
			keys.add("in_hospital_day_number");
			keys.add("str_5");
			keys.add("int_last_in_hospital_interval");

			keys.add("str_5_diagname");
			keys.add("main_hqms_diag_code");
			keys.add("str_hqms_main_diag");
			List<Map<String, String>> datas = solrService.unplanReHospitalExportExcel(params);
			ExcelUtils.exportExcel1(out,headers, keys, datas);
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}

	//非计划再手术导出
	@GetMapping("/unplan_re_operate_export_excel")
	public void unplanReOperateExportExcel(StatisticsAnalysisQuery params,HttpServletResponse response){
		OutputStream out = null;
		try{
			params.setPageSize(null);
			/*
			medicalRecords = medicalRecordDRGsService.getCodingExport(params);*/
			response.setContentType("applicationnd.ms-excel");
			String title= "非计划再手术记录导出"+DateUtil.dateFormat(new Date());
			StringBuilder downLoadFileName = new StringBuilder();
			downLoadFileName = new StringBuilder(
					"attachment;filename=");
			downLoadFileName.append(title)
					.append(".xls");
			String encodeStr = new String(downLoadFileName.toString().getBytes(
					"GB2312"), "ISO_8859_1");
			response.addHeader("Content-Disposition", encodeStr);
			out = response.getOutputStream();
			List<String> headers = new ArrayList<String>();
			headers.add("住院号");
			headers.add("姓名");
			headers.add("病案号");
			headers.add("住院次数");
			headers.add("出生日期");
			headers.add("证件号码");
			headers.add("出院科室");
			headers.add("出院日期");
			headers.add("离院方式");
			headers.add("住院费用");
			headers.add("血费");
			headers.add("手术费");
			headers.add("住院天数");
			headers.add("手术编码");
			headers.add("手术名称");
			headers.add("是否非计划再手术");
			headers.add("非计划再手术间隔");
			headers.add("非计划再手术原因");
			List<String> keys = new ArrayList<String>();
			keys.add("only_id");
			keys.add("patient_name");
			keys.add("mr_id");
			keys.add("visit_number");
			keys.add("birthday");
			keys.add("id_number");
			keys.add("out_dept_name");
			keys.add("out_hospital_date");
			keys.add("out_hospital_type");
			keys.add("cost1");//总费用
			keys.add("cost22");//血费
			keys.add("cost13");//手术费
			keys.add("in_hospital_day_number");

			keys.add("un_planed_resurgery_operate_code");
			keys.add("un_planed_resurgery_operate_name");
			keys.add("un_planed_resurgery");
			keys.add("un_planed_resurgery_interval");
			keys.add("main_surgical_un_plan_reason");
			List<Map<String, String>> datas = solrService.unplanReOperateExportExcel(params);
			ExcelUtils.exportExcel1(out,headers, keys, datas);
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}

	/**
	 * 非计划再住院统计
	 * @param params
	 * @return
	 */
	@GetMapping("/unplan_re_hospital")
	@ResponseBody
	public RespondResult unplanReHospital(StatisticsAnalysisQuery params){
		RespondResult respondResult = null;
		try {
			List<Map<String,Object>> datas = solrService.unplanReHospital(params);
			params.setTotalCounts(datas.size());
			params.setDatas(datas);
			/*List<Integer> pageTypeIds = printService.getMrPageTypeIdsByPrintTypeId(printerTypeId);*/
			respondResult = new RespondResult(true, RespondResult.successCode, "查询成功", params);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			respondResult = new RespondResult(false, RespondResult.errorCode, e.getMessage(),e.getMessage());
		}

		return respondResult;
	}

	/**
	 * 非计划再手术统计
	 * @param params
	 * @return
	 */
	@GetMapping("/unplan_re_operate")
	@ResponseBody
	public RespondResult unplanReOperate(StatisticsAnalysisQuery params){
		RespondResult respondResult = null;
		try {
			List<Map<String,Object>> datas = solrService.unplanReOperate(params);
			params.setTotalCounts(datas.size());
			params.setDatas(datas);
			/*List<Integer> pageTypeIds = printService.getMrPageTypeIdsByPrintTypeId(printerTypeId);*/
			respondResult = new RespondResult(true, RespondResult.successCode, "查询成功", params);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			respondResult = new RespondResult(false, RespondResult.errorCode, e.getMessage(),e.getMessage());
		}

		return respondResult;
	}

	/**
	 * 二级医院重点手术
	 * @param params
	 * @return
	 */
	@GetMapping("/seven_key_surgery")
	@ResponseBody
	public RespondResult sevenKeySurgery(StatisticsAnalysisQuery params){
		RespondResult respondResult = null;
		try {
			List<Map<String,Object>> datas = solrService.sevenKeySurgery(params);
			params.setTotalCounts(datas.size());
			params.setDatas(datas);
			/*List<Integer> pageTypeIds = printService.getMrPageTypeIdsByPrintTypeId(printerTypeId);*/
			respondResult = new RespondResult(true, RespondResult.successCode, "查询成功", params);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			respondResult = new RespondResult(false, RespondResult.errorCode, e.getMessage(),e.getMessage());
		}

		return respondResult;
	}

	@GetMapping("/seven_key_surgery_export_excel")
	public void surgeryKeyDiseasesExportExcel(StatisticsAnalysisQuery params,HttpServletResponse response){
		OutputStream out = null;
		try{
			params.setPageSize(null);
			/*
			medicalRecords = medicalRecordDRGsService.getCodingExport(params);*/
			response.setContentType("applicationnd.ms-excel");
			String title= "二级医院重点手术"+params.getKeySurgeryCode()+"导出"+DateUtil.dateFormat(new Date());
			StringBuilder downLoadFileName = new StringBuilder();
			downLoadFileName = new StringBuilder(
					"attachment;filename=");
			downLoadFileName.append(title)
					.append(".xls");
			/*downLoadFileName.append(title).append(DateUtil.dateFormat(new Date()))
			.append(".dbf");*/
			String encodeStr = new String(downLoadFileName.toString().getBytes(
					"GB2312"), "ISO_8859_1");
			response.addHeader("Content-Disposition", encodeStr);
			out = response.getOutputStream();
			List<String> headers = new ArrayList<String>();
			headers.add("住院号");
			headers.add("姓名");
			headers.add("出院日期");
			headers.add("出院病区名称");
			headers.add("是否死亡");
			headers.add("住院天数");
			headers.add("是否术后（15天内）非预期再手术");
			headers.add("主要手术名称");
			headers.add("主要手术编码");
			headers.add("总费用");
			List<String> keys = new ArrayList<String>();
			keys.add("only_id");
			keys.add("patient_name");
			keys.add("out_hospital_date");
			keys.add("out_dept_name");
			keys.add("is_death");
			keys.add("in_hospital_day_number");
			keys.add("is_15_resurgery");
			keys.add("main_surgery");
			keys.add("main_surgery_code");
			keys.add("total_cost");
			List<Map<String, String>> datas = solrService.sevenKeySurgeryForExport(params);
			ExcelUtils.exportExcel1(out,headers, keys, datas);
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}

	/**
	 * 三级医院重点手术
	 * @param params
	 * @return
	 */
	@GetMapping("/tertiary_hospital_key_surgery")
	@ResponseBody
	public RespondResult tertiaryHospitalKeySurgery(StatisticsAnalysisQuery params){
		RespondResult respondResult = null;
		try {
			List<Map<String,Object>> datas = solrService.tertiaryHospitalKeySurgery(params);
			params.setTotalCounts(datas.size());
			params.setDatas(datas);
			/*List<Integer> pageTypeIds = printService.getMrPageTypeIdsByPrintTypeId(printerTypeId);*/
			respondResult = new RespondResult(true, RespondResult.successCode, "查询成功", params);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			respondResult = new RespondResult(false, RespondResult.errorCode, e.getMessage(),e.getMessage());
		}

		return respondResult;
	}


	@GetMapping("/tertiary_hospital_key_surgery_export_excel")
	public void tertiaryHospitalKeyDiseasesExportExcel(StatisticsAnalysisQuery params,HttpServletResponse response){
		OutputStream out = null;
		try{
			params.setPageSize(null);
			/*
			medicalRecords = medicalRecordDRGsService.getCodingExport(params);*/
			response.setContentType("applicationnd.ms-excel");
			String title= "三级医院重点手术"+params.getKeySurgeryCode()+"导出"+DateUtil.dateFormat(new Date());
			StringBuilder downLoadFileName = new StringBuilder();
			downLoadFileName = new StringBuilder(
					"attachment;filename=");
			downLoadFileName.append(title)
					.append(".xls");
			/*downLoadFileName.append(title).append(DateUtil.dateFormat(new Date()))
			.append(".dbf");*/
			String encodeStr = new String(downLoadFileName.toString().getBytes(
					"GB2312"), "ISO_8859_1");
			response.addHeader("Content-Disposition", encodeStr);
			out = response.getOutputStream();
			List<String> headers = new ArrayList<String>();
			headers.add("住院号");
			headers.add("姓名");
			headers.add("出院日期");
			headers.add("出院病区名称");
			headers.add("是否死亡");
			headers.add("住院天数");
			headers.add("是否术后（15天内）非预期再手术");
			headers.add("主要手术名称");
			headers.add("主要手术编码");
			headers.add("总费用");
			List<String> keys = new ArrayList<String>();
			keys.add("only_id");
			keys.add("patient_name");
			keys.add("out_hospital_date");
			keys.add("out_dept_name");
			keys.add("is_death");
			keys.add("in_hospital_day_number");
			keys.add("is_15_resurgery");
			keys.add("main_surgery");
			keys.add("main_surgery_code");
			keys.add("total_cost");
			List<Map<String, String>> datas = solrService.tertiaryHospitalKeySurgeryForExport(params);
			ExcelUtils.exportExcel1(out,headers, keys, datas);
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}


	/**
	 * 三级医院恶性肿瘤
	 * @param params
	 * @return
	 */
	@GetMapping("/tertiary_hospital_malignant_tumor")
	@ResponseBody
	public RespondResult tertiaryHospitalMalignantTumor(StatisticsAnalysisQuery params){
		RespondResult respondResult = null;
		try {
			List<Map<String,Object>> datas = solrService.tertiaryHospitalMalignantTumor(params);
			params.setTotalCounts(datas.size());
			params.setDatas(datas);
			/*List<Integer> pageTypeIds = printService.getMrPageTypeIdsByPrintTypeId(printerTypeId);*/
			respondResult = new RespondResult(true, RespondResult.successCode, "查询成功", params);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			respondResult = new RespondResult(false, RespondResult.errorCode, e.getMessage(),e.getMessage());
		}

		return respondResult;
	}

	@GetMapping("/tertiary_hospital_malignant_tumor_export_excel")
	public void tertiaryHospitalMalignantTumorExportExcel(StatisticsAnalysisQuery params,HttpServletResponse response){
		OutputStream out = null;
		try{
			params.setPageSize(null);
			/*
			medicalRecords = medicalRecordDRGsService.getCodingExport(params);*/
			response.setContentType("applicationnd.ms-excel");
			String title= "三级医院恶性肿瘤"+params.getKeySurgeryCode()+"导出"+DateUtil.dateFormat(new Date());
			StringBuilder downLoadFileName = new StringBuilder();
			downLoadFileName = new StringBuilder(
					"attachment;filename=");
			downLoadFileName.append(title)
					.append(".xls");
			/*downLoadFileName.append(title).append(DateUtil.dateFormat(new Date()))
			.append(".dbf");*/
			String encodeStr = new String(downLoadFileName.toString().getBytes(
					"GB2312"), "ISO_8859_1");
			response.addHeader("Content-Disposition", encodeStr);
			out = response.getOutputStream();
			List<String> headers = new ArrayList<String>();
			headers.add("住院号");
			headers.add("姓名");
			headers.add("出院日期");
			headers.add("出院病区名称");
			headers.add("是否死亡");
			headers.add("住院天数");
			headers.add("是否术后（15天内）非预期再手术");
			headers.add("主要诊断名称");
			headers.add("主要诊断编码");
			headers.add("主要手术名称");
			headers.add("主要手术编码");
			headers.add("总费用");
			List<String> keys = new ArrayList<String>();
			keys.add("only_id");
			keys.add("patient_name");
			keys.add("out_hospital_date");
			keys.add("out_dept_name");
			keys.add("is_death");
			keys.add("in_hospital_day_number");
			keys.add("is_15_resurgery");
			keys.add("main_diag");
			keys.add("main_diag_code");
			keys.add("main_surgery");
			keys.add("main_surgery_code");
			keys.add("total_cost");
			List<Map<String, String>> datas = solrService.tertiaryHospitalMalignantTumorForExport(params);
			ExcelUtils.exportExcel1(out,headers, keys, datas);
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
}
